package com.attendance.chdingtask.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.attendance.chdingtask.dao.BaseJPA;
import com.attendance.chdingtask.dao.DataListDao;
import com.attendance.chdingtask.model.DataList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DataListService extends BaseService<DataList,Long> {
    @Autowired
    private DataListDao dao;
    @Override
    protected BaseJPA<DataList> getDao() {
        return dao;
    }
    public void saveDataList(JSONObject obj) {
        System.out.println(obj);
        JSONArray arr=obj.getJSONArray("DataList");
        List<DataList> lists=new ArrayList<>();
        if(null != arr&& arr.size()>0){
            for(int i=0;i<arr.size();i++){
                JSONObject object=arr.getJSONObject(i);
                DataList dataList=JSONObject.parseObject(object.toJSONString(),DataList.class);
                List<DataList> list=dao.findAllByBizId(dataList.getBizId());
                if(null != list&& list.size()>0){
                    continue;
                }
                save(dataList);
                lists.add(dataList);

            }
        }
//        if(null != lists&& lists.size()>0){
//            saveAll(lists);
//        }
    }
}
